﻿@using Orchard.ContentManagement;
@model Associativy.TagsAdapter.Models.AssociativyTagGraphPart

<fieldset>
    <legend>@T("Tag graph settings")</legend>
    <ol>
        <li>
            @Html.EditorFor(m => m.IsTagGraph)
            <label for="@Html.FieldIdFor(m => m.IsTagGraph)" class="forcheckbox">@T("This is a Tag Graph")</label>
            @Html.ValidationMessageFor(m => m.IsTagGraph)
        </li>
    </ol>
</fieldset>
@*Already saved*@
@if (Model.Id != 0)
{
    Script.Require("jQuery").AtFoot();
    using (Script.Foot())
    {
        <script type="text/javascript">
            (function ($) {
                $.extend(true, {
                    associativy: {
                        processTaggedItems: function () {
                            $("#button\\.ProcessTaggedItems").attr("disabled", "disabled");
                            var url = '@Url.Action("ProcessTaggedItems", new { Controller = "Admin", Area = "Associativy.TagsAdapter", GraphName = Model.As<Associativy.Administration.Models.AssociativyGraphPart>().GraphName })';
                            var postData = { __RequestVerificationToken: "@Html.AntiForgeryTokenValueOrchard()" };
                            $.post(url, postData, function (response) {
                                window.location.reload();
                            });
                        }
                    }
                });
            })(jQuery);
        </script>
    }

    <fieldset>
        <button type="button" id="button.ProcessTaggedItems" name="button.ProcessTaggedItems" value="ProcessTaggedItems"
            onclick="$.associativy.processTaggedItems(); return false;">@T("Process all tagged and contained items")</button>
        <span class="hint">@T("This will process all tagged content item stored in the graph and e.g. add new connections.")</span>
    </fieldset>   
}